package com.cy.pj.notice.web.advice;

import com.cy.pj.notice.web.pojo.JsonResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

//标记为全局异常类
@RestControllerAdvice
public class GlobalExceptionHandler {
    public static final Logger log =
            LoggerFactory.getLogger(GlobalExceptionHandler.class);
                    //此处为传入的异常
    @ExceptionHandler(RuntimeException.class)
                                            //此处为真正可以处理的异常
    public JsonResult doHandleRuntimeException(RuntimeException e){
        //在控制台输出异常;
        e.printStackTrace();
        //打印日志把异常写入大括号中
        log.error("exception mg is {}",e.getMessage());
        //返回封装了异常状态和信息对象;
        return new JsonResult(e);
    }


//    @ExceptionHandler(ServiceException.class)
//    public JsonResult doHandleServiceException(ServiceException e){
//        //在控制台输出异常;
//        e.printStackTrace();
//        //打印日志把异常写入大括号中
//        log.error("exception mg is {}",e.getMessage());
//        //返回封装了异常状态和信息对象;
//        return new JsonResult(e);
//    }

}
